import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-10-03
 * Time: 11:36
 */
public class Test {
    public static void main(String[] args) {
        //纯Key模型
        TreeSet<String> set = new TreeSet<>();
        set.add("world");
        set.add("haha");
        set.add("abc");
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
    }

    public static void main2(String[] args) {
        //key-value模型
        TreeMap<String, Integer> treeMap = new TreeMap<>();
        treeMap.put("abc", 1);
        treeMap.put("haha", 30);
        treeMap.put("world", 3);
        //public Set<Map.Entry<K,V>> entrySet() {
        Set<Map.Entry<String, Integer>> entrySet = treeMap.entrySet(); //返回所有的 key-value 映射关系
        for (Map.Entry<String, Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() + " val: " + entry.getValue());
        }

        Integer val = treeMap.get("hello");
        System.out.println(val);// 返回一个null
        Integer val1 = treeMap.getOrDefault("hello", 10);
        System.out.println(val1);// 返回一个指定的默认值10
        Integer val3 = treeMap.remove("haha");
        System.out.println(val3);// 30
        boolean val4 = treeMap.remove("world", 2);
        System.out.println(val4); //false
    }

    public static void main1(String[] args) {
        BinarySearchTree bst = new BinarySearchTree();
        bst.insert(10);
        bst.insert(5);
        bst.insert(15);
        bst.insert(9);
        bst.insert(3);
        bst.insert(18);

        bst.remove(10);
    }
}
